﻿using System;
using Glue;
using Xunit;

namespace GlueTests.MappingTests
{
    public class When_adding_a_nested_relation_between_same_type
    {
        public class GuiPerson { public Address Address { get; set; } }
        public class DomainPerson { public Address Address { get; set; } }

        public class Address { public String City { get; set; } }

        private readonly Mapping<DomainPerson, GuiPerson> personMapping;

        public When_adding_a_nested_relation_between_same_type()
        {
            personMapping = new Mapping<DomainPerson, GuiPerson>();
        }

        [Fact]
        public void Should_not_succeed_without_a_mapper()
        {
            Assert.Throws(typeof(GlueException),()=> personMapping.Relate(domain => domain.Address, gui => gui.Address));
        }

        [Fact]
        public void Should_succeed_with_a_mapper()
        {
            var addressMapper = new Mapping<Address, Address>();
            addressMapper.AutoRelateEqualNames();
            personMapping.Relate(domain => domain.Address, gui => gui.Address, addressMapper);
        }
    }
}
